/** 
* Copyright (C) 2012-2017 ZEEI Inc.All Rights Reserved.
* 项目名称：efs
* 文件名称：AlarmCodeController.java
* 包  名  称：com.zeei.efs.controller
* 文件描述：TODO 请修改文件描述
* 创建日期：2017年6月8日下午1:47:43
* 
* 修改历史
* 1.0 chenhuiqiong 2017年6月8日下午1:47:43 创建文件
*
*/


package com.zeei.app.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.zeei.app.service.EnterpriseService;
import com.zeei.app.service.MyCollectService;
import com.zeei.app.vo.EnterpriseVO;
import com.zeei.app.vo.MyCollectVO;
import com.zeei.common.annotation.SysLog;
import com.zeei.common.controller.BasicController;
import com.zeei.common.enums.LogType;
import com.zeei.common.utils.SessionInfoUtil;
import com.zeei.common.vo.PageParamVO;
import com.zeei.common.vo.ResultRowsVO;
import com.zeei.common.vo.UserVO;


/**
 * 
* 类型名称：AppVersionController
* 类型描述：APP版本管理
* 功能描述：APP版本管理
* 创建作者：chenhuiqiong
*
 */
@Controller
@RequestMapping("/app/enterprise")
public class EnterpriseController extends BasicController{
	@Autowired
	private EnterpriseService enterpriseService;
	@Autowired
	private MyCollectService myCollectService;
	
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	@SysLog(text = "查询企业污染源基本信息", type = LogType.View)
	public ResultRowsVO<EnterpriseVO> queryEnterpriseList(EnterpriseVO enterpriseVO, PageParamVO pageParam){
		PageInfo<EnterpriseVO> listData = enterpriseService.queryEnterpriseList(enterpriseVO, pageParam, true);
		List<EnterpriseVO> enterpriseList = listData.getList();
		return createResultRowsVO(enterpriseList, true, "",(int)listData.getTotal());
	}
	
	@RequestMapping(value = "/listAll", method = RequestMethod.POST)
	@ResponseBody
	@SysLog(text = "查询全部企业污染源基本信息", type = LogType.View)
	public ResultRowsVO<EnterpriseVO> queryEnterpriseListAll(EnterpriseVO enterpriseVO, PageParamVO pageParam){
		PageInfo<EnterpriseVO> listData = enterpriseService.queryEnterpriseList(enterpriseVO, pageParam, false);
		List<EnterpriseVO> enterpriseList = listData.getList();
		
		UserVO user = SessionInfoUtil.getSessionUserInfo();
		MyCollectVO myCollectVO = new MyCollectVO();
	    	myCollectVO.setUserId(user.getUserid());
		PageInfo<MyCollectVO> collectData = myCollectService.queryMyCollect(myCollectVO, pageParam, false);
		List<MyCollectVO> myCollectList = collectData.getList();
		
		for(EnterpriseVO enterprise : enterpriseList){
		    myCollectList.stream().filter(s -> enterprise.getPsCode().equals(s.getPsCode())).forEach(s -> enterprise.setCollect(true));
		}
		
		return createResultRowsVO(enterpriseList, true, "",(int)listData.getTotal());
	}
	
	
}

